package org.hamsandwich.example.testMatchers;

import org.junit.Ignore;
import org.junit.Test;

import static org.hamcrest.Matchers.*;
import static org.hamsandwich.example.testMatchers.AppleMatchers.*;
import static org.hamsandwich.hamcrest_to_junit_generics_mismatch.WildcardExtendsT.assertThat;

/**
 * With library usage. Wwe can now combine all sub-matchers (with implicitly allOf()) and cross-field validation into a single assertThat call.
 * The second test (Ignored) demonstrates the formatted error messages.
 */
public class NewAppleTest {

    @Test
    public void ripensCorrectly() throws Exception {
        //given
        Apple apple = new Apple(Brand.Coxes);

        //when
        apple.ripen();

        //then
        assertThat(apple, allOf(
                brand(is(equalTo(Brand.Coxes)), is(not(equalTo(Brand.GoldenDelicious)))),   // implicit allOf logic
                is(not(perfectlyRipe())),                                                   // internal cross-field validation
                is(theSameColourAsAPerfectlyRipe(Brand.GrannySmith)))
        );
    }

    /**
     * Un-ignore this test to show the nice assertion messages generated by the matcher
     */
    @Test
    @Ignore
    public void ripensCorrectly_willFail() throws Exception {
        //given
        Apple apple = new Apple(Brand.Coxes);

        //when
        apple.ripen();

        //then
        assertThat(apple, allOf(
                brand(is(equalTo(Brand.Coxes)), is(not(equalTo(Brand.GoldenDelicious)))),
                is(perfectlyRipe()),                                                     // *will fail as is over-ripe*
                is(theSameColourAsAPerfectlyRipe(Brand.GrannySmith)))
        );
    }


}